const GameObjects = [];

export class GameObject {
    constructor(){
        GameObjects.push(this); //整体按一个队列来处理，先来先服务super的时候push
        this.has_called_start = false;
    }

    start(){

    }

    update(){

    }
    
    on_destroy(){

    }
    destroy(){
        this.on_destroy;

        for(let i in GameObjects){
            const obj = GameObjects[i];
            if(obj === this)
            {
                GameObjects.splice(i);
                break;
            }
        }
    }
}
const step = ()=>{

    for(let obj of GameObjects){
        if(!obj.has_called_start){
            obj.has_called_start = true;
            obj.start();
        }else{
            obj.update();
        }
    }

    requestAnimationFrame(step);
}

requestAnimationFrame(step);